package com.company;

import java.util.Scanner;

public class DelimitersDemo             //分隔符演示
{
    public static void main(String[] args)
    {
        Scanner keyboard1 = new Scanner(System.in);
        Scanner keyboard2 = new Scanner(System.in);

        keyboard2.useDelimiter("##");
        //The delimiters for keyboard1 are the white space characters. keyboard1的分隔符是空白字符。
        //The only delimiter for keyboard2 is ##.        keyboard2的唯一分隔符是##。
        //默认情况下，Scanner是使用“空白”作为分隔符将输入分解为标记，然后使用它所提供的不同的next方法将得到的标记转换为不同的类型的值。
        //Scanner.useDelimiter( )方法，可以将分隔符号修改为"回车"，或者其他字符。
        String s1;
        String s2;

        System.out.println("Enter a line of text with two words:");         //输入一行包含两个单词的文本
        s1 = keyboard1.next( );
        s2 = keyboard1.next( );
        System.out.println("The two words are \"" + s1 +
                "\" and \"" + s2 + "\"");

        System.out.println("Enter a line of text with two words");          //输入一行包含两个单词的文本
        System.out.println("delimited by ##:");                             //由# #分隔开的
        s1 = keyboard2.next( );
        s2 = keyboard2.next( );
        System.out.println("The two words are \"" + s1 +
                "\" and \"" + s2 + "\"");
    }
}